﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using Sebarf.Core.Interfaces;
using Sebarf.Services.Interfaces;
using Sebastof.Serialisation;
using Sebastof.Services.Interfaces;
using Utils;

#endregion

namespace Sebastof.ProcessChains.ProcessSteps {
	/// <summary>
	/// This is another processing step (for single objects).
	/// Every object transfered will here be put into a lookup table (id->object | object->id).
	/// </summary>
	public class ObjectMapperStep : ProcessStep<ObjectTransportContainer> {
		#region Public Properties

		[ServiceRequest]
		public IServiceLocatorService ServiceLocatorService { get; set; }

		[ServiceRequest]
		public IObjectMappingRegisterService ObjectMappingRegisterService { get; set; }

		#endregion

		#region Public Methods

		public ObjectMapperStep(IServiceLocatorService m) {
			ServiceLocatorService = m;
			ObjectMappingRegisterService = m.GetRegisteredService<IObjectMappingRegisterService>();
		}

		public ObjectMapperStep() {
		}

		protected override ObjectTransportContainer OnProcess(ObjectTransportContainer toProcess) {
			if (toProcess.Value is ValueType || toProcess.Value is String || toProcess.Value == null) {
			}
			else {
				var key = toProcess.TransferedMetadata.GetMetadata<string>(toProcess.Value, "UniqueIdentifier");
				ObjectMappingRegisterService.AddMapping(key, toProcess.Value);
			}
			return base.OnProcess(toProcess);
		}

		#endregion

		#region Private Fields

		private IServiceLocatorService m_m;

		#endregion
	}
}